package com.itic.im.core.constants;

import java.util.stream.Stream;

public enum MsgTypeEnum {
    /**
     * text
     */
    TEXT("1", "TEXT"),

    /**
     * PICTURE
     */
    PICTURE("2", "PICTURE"),

    /**
     * VIDEO
     */
    VIDEO("3", "VIDEO"),

    /**
     * FILE
     */
    FILE("4", "FILE"),

    /**
     * CHATRECORD
     */
    CHATRECORD("5", "CHATRECORD");

    public String code;

    public String name;

    MsgTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static MsgTypeEnum valueOfMsgType(String code) {
        return Stream.of(values())
                .filter(msgType -> msgType.getCode().equals(code))
                .findFirst()
                .orElse(null);
    }

    public static MsgTypeEnum nameOfMsgType(String name) {
        return Stream.of(values())
                .filter(msgType -> msgType.getName().equals(name))
                .findFirst()
                .orElse(null);
    }
}
